package sound 
{
	 import com.gaiaframework.api.Gaia;
	 import com.greensock.*;
	 import com.greensock.events.LoaderEvent;
	 import com.greensock.loading.*;
	 import flash.display.MovieClip;
	 import flash.display.Shape;
	 import flash.events.Event;
	 import pages.Pages;
	 import ui.videos.SeekAudio;
	 import utils.ShapeUtil;
	/**
	 * ...
	 * @author usual
	 */
	public class SoundManager 
	{
		private var _sound:MP3Loader;
		private var _soundVolume:SeekAudio;
		private var _containerSeekAudio:MovieClip;
		public function SoundManager() 
		{
			_sound = new MP3Loader(Gaia.api.getPage(Pages.HOME).assets.soundFile.src, { name:"generalSound", repeat: -1,volume:0.5, autoPlay:false, onComplete:completeHandler } );
			_sound.load();
			_containerSeekAudio = new MovieClip();
			Gaia.api.getPage(Pages.NAV).content.footer.addChild(_containerSeekAudio);
			_soundVolume = new SeekAudio(false);
			_soundVolume.videoPlayer = _sound;
			_containerSeekAudio.addChild(_soundVolume);
			var sp:Shape = ShapeUtil.getLineV(17, 0x8d8b8b);
			_containerSeekAudio.addChild(sp);
			_soundVolume.x = sp.x + sp.width + 17;
			Gaia.api.getPage(Pages.NAV).content.stage.addEventListener(Event.RESIZE, _onResize);
			_onResize()
		}
		
		private function _onResize(e:Event=null):void 
		{
			_containerSeekAudio.x = int(Gaia.api.getPage(Pages.NAV).content.stage.stageWidth - (_containerSeekAudio.width + 24));
			_containerSeekAudio.y = 10;
		}
		
		private function completeHandler(event:LoaderEvent):void 
		{
			_sound.playSound();
		}
		public function set volume(vol:Number):void
		{
			
		}
		public function initGeneralSound():void
		{
			_sound.playSound();
		}
		public function toggleSound():void
		{
			_sound.soundPaused = !_sound.soundPaused;
		}
		public function destroy():void
		{
			_sound.dispose();
			Gaia.api.getPage(Pages.NAV).content.footer.removeChild(_containerSeekAudio);
			Gaia.api.getPage(Pages.NAV).content.stage.removeEventListener(Event.RESIZE, _onResize);
			
			
		}
	}

}